import Vue from 'vue'
import Router from 'vue-router'
import Approval from './modules/approval'
import Attendance from './modules/attendance'
import Department from './modules/department'
import Employee from './modules/employee'
import Permission from './modules/permission'
import Role from './modules/role'
import Salary from './modules/salary'
import Social from './modules/social'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/test',
    component: Layout,
    children: [
      // {
      //   path: 'test',
      //   name: 'test',
      //   component: () => import('@/views/test/index'),
      //   meta: { title: '测试页面', icon: 'dashboard' }
      // },
      // /test/123  /test/456
      // /test/123?a=1&b=2
      // this.$route.params.id
      // this.$route.query
      {
        // path: '/test/:id',  这种叫普通的动态路由， 工作里面一般有复杂的动态路由， 正则匹配
        // path: '/test/:id?',
        path: '/test/:id*',
        name: 'test222',
        component: () => import('@/views/test/index'),
        meta: { title: '测试页面222', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  Department,
  Role,
  Employee,
  Permission,

  Approval,
  Attendance,
  Salary,
  Social,

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
